package org.elsfs.auth.jackson2;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import java.io.IOException;
import org.springframework.security.oauth2.server.authorization.settings.OAuth2TokenFormat;

/**
 * 定义序列化{@link OAuth2TokenFormat}
 *
 * @author zeng
 * @since 0.0.1
 */
public final class Oauth2TokenFormatSerializer extends StdSerializer<OAuth2TokenFormat> {
  public Oauth2TokenFormatSerializer() {
    this(null);
  }

  public Oauth2TokenFormatSerializer(Class<OAuth2TokenFormat> t) {
    super(t);
  }

  @Override
  public void serialize(OAuth2TokenFormat value, JsonGenerator gen, SerializerProvider provider)
      throws IOException {
    if (value == null) {
      gen.writeNull();
      return;
    }
    // 直接输入领导人姓名，不需要起始和结束的花括号
    gen.writeString(value.getValue());
  }
}
